package com.example.android.stargazeeffect;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class Star 
{
	private Paint _paint = new Paint(Paint.ANTI_ALIAS_FLAG);
	
	private int _screenWidth = 0;
	private int _screenHeight = 0;
	private int _x = 0;
	private int _y = 0;
	private int _z = 0;
	
	public Star(int width, int height)
	{
		_screenWidth = width;
		_screenHeight = height;
		_paint.setStyle(Paint.Style.FILL);
		
		initStar(0);
	}
	
	public void draw(Canvas canvas)
	{
		_x -= _z;
		
		canvas.drawRect(_x, _y, (_x + _z), (_y + _z), _paint);
		
		if(_x < 0)
		{
			initStar(_screenWidth);
		}
	}
	
	private void initStar(int width)
	{
		if (width == 0)
		{
			_x = (int)(Math.random() * _screenWidth);
		}
		else
		{
			_x = width;
		}
		_y = (int)(Math.random() * _screenHeight);
		_z = (int)(Math.random() * 3) +1;
	
		_paint.setColor(Color.WHITE);
	}
}
